package com.zzvcom.webapp.action.admin;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.zzvcom.persist.model.admin.ProductQuality;
import com.zzvcom.service.admin.ProductQualityManager;
import com.zzvcom.template.ResultPage;
import com.zzvcom.utils.ExtMessage;

@Controller
@Scope("prototype")
public class ProductQualityAction
{

	private ProductQuality quality;

	private ProductQualityManager manager;

	private ExtMessage msg = new ExtMessage();// 返回信息
	private Map rs = new HashMap();// 结果集合
	private ResultPage resultPage;
	private Integer start;

	private Integer limit;

	public Integer getStart()
	{
		return start;
	}

	public void setStart(Integer start)
	{
		this.start = start;
	}

	public Integer getLimit()
	{
		return limit;
	}

	public void setLimit(Integer limit)
	{
		this.limit = limit;
	}

	public String execute()
	{
		if (resultPage == null)
		{
			resultPage = new ResultPage();
		}
		resultPage.startLimitSetting(start, limit);
		DetachedCriteria dc = DetachedCriteria.forClass(ProductQuality.class);
		dc.addOrder(Order.asc("seq"));
		resultPage.setDetachedCriteria(dc);
		manager.getResultPageByDetachedCriteria(resultPage);
		rs.put("root", resultPage.getResult());
		rs.put("records", resultPage.getTotalRecord());
		return "rs";
	}

	public String save()
	{
		if (StringUtils.isBlank(quality.getId()))
		{
			quality.setId(null);
		}
		manager.save(quality);
		msg.setInfo("保存成功");
		return "msg";
	}

	public String delete()
	{
		quality = manager.get(quality.getId());
		manager.delete(quality);
		msg.setInfo("删除成功");
		return "msg";
	}



	public ProductQuality getQuality()
    {
        return quality;
    }

    public void setQuality(ProductQuality quality)
    {
        this.quality = quality;
    }

    public ExtMessage getMsg()
    {
        return msg;
    }

    public void setMsg(ExtMessage msg)
    {
        this.msg = msg;
    }

    public Map getRs()
    {
        return rs;
    }

    public void setRs(Map rs)
    {
        this.rs = rs;
    }

    public ResultPage getResultPage()
    {
        return resultPage;
    }

    public void setResultPage(ResultPage resultPage)
    {
        this.resultPage = resultPage;
    }

    public ProductQualityManager getManager()
    {
        return manager;
    }

    @Autowired
	public void setManager(ProductQualityManager manager)
	{
		this.manager = manager;
	}



}
